//
//  Flow.swift
//  Employee
//
//  Created by swordjoy on 2017/6/26.
//  Copyright © 2017年 remotevillage. All rights reserved.
//

import Foundation
import SwiftyJSON

struct Flow: ModelProtocol {
  
  let id: String
  let name: String
  let flowTypeDtos: [FlowType]
  
  init(id: String, name: String) {
    self.id = id
    self.name = name
    self.flowTypeDtos = []
  }
  
  init(json: JSON) {
    self.id = json["id"].stringValue
    self.name = json["name"].stringValue
    self.flowTypeDtos = FlowType.array(from: json["flowTypeDtos"].arrayValue)
  }
  
  static func array(from jsonArray: [JSON]) -> [Flow] {
    return jsonArray.map({
      return Flow(json: $0)
    })
  }
}

struct FlowType: ModelProtocol {
  let id: String
  let name: String
  
  init(json: JSON) {
    self.id = json["id"].stringValue
    self.name = json["name"].stringValue
  }
  
  static func array(from jsonArray: [JSON]) -> [FlowType] {
    return jsonArray.map({
      return FlowType(json: $0)
    })
  }
}
